package clam.apps.adu.activity;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MenuLateral implements OnItemClickListener{
	private ListView lv_menu;
	private ActionBarDrawerToggle drawerToggle;
	private DrawerLayout drawerLayout;
	private Activity activity;
	
	public MenuLateral(Activity activity) 
	{
		this.activity = activity;
		
		// recupère les instances drawer_layout et lv_menu
	    drawerLayout = (DrawerLayout)this.activity.findViewById(R.id.drawer_layout);
	    lv_menu = (ListView)this.activity.findViewById(R.id.menu);
	 
	    // création du menu slide
	    lv_menu.setAdapter(new ArrayAdapter(this.activity, android.R.layout.simple_list_item_1, new String[]{this.activity.getString(R.string.dernieres_anecdote), this.activity.getString(R.string.poster_anecdote), this.activity.getString(R.string.informations_contact)}));
	 
	    // permet de cliquer sur les item du menu
	    drawerToggle = new ActionBarDrawerToggle(this.activity, drawerLayout, R.drawable.ic_launcher, R.string.open_menu, R.string.close_menu);
	 
	    //Définit drawerToogle comme le DrawerListener du layout
	    drawerLayout.setDrawerListener(drawerToggle);
	 
	    //Définit l'icône comme cliquable et ajoute une flèche vers la gauche 
	    this.activity.getActionBar().setDisplayHomeAsUpEnabled(true);
	    
	    // ajoute un écouteur au menu
	    lv_menu.setOnItemClickListener((OnItemClickListener) this);
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		//ferme le menu
		drawerLayout.closeDrawers();
		switch(position)
		{
			case 0:
				//lance l'application dernieresAnecdotes
				this.activity.startActivity(new Intent(this.activity, DernieresAnecdotesActivity.class));
				// termine l'activity en cours 
				this.activity.finish();
			break;
			case 1:
				//lance l'application posterAnecdote
				this.activity.startActivity(new Intent(this.activity, PosterAnecdoteActivity.class));
				// termine l'activity en cours
				this.activity.finish();
			break;
			case 2:
				//lance l'application contact
				this.activity.startActivity(new Intent(this.activity, ContactActivity.class));
				// termine l'activity en cours
				this.activity.finish();
			break;
		}
	}
	
	public ActionBarDrawerToggle getDrawerToggle() {
		return drawerToggle;
	}

	public void setDrawerToggle(ActionBarDrawerToggle drawerToggle) {
		this.drawerToggle = drawerToggle;
	}
}
